<?php

###########################################################################
#   Copyright (C) 2012 CDNPAL LTD by Christopher Gu                       #
#   resources@cdnpal.com                                                  #
#                                                                         #
#   coded for Php 4.3/5.X and above                                       #
#   and AllowOverride all for .htaccess                                   #
#                                                                         #
#   This program is free software released                                #
#   under the GPL version 2 license:                                      #
#   http://www.gnu.org/licenses/gpl-2.0.htm                               #
#                                                                         #
#   This program is distributed WITHOUT ANY WARRANTY                      #
#   or FITNESS FOR A PARTICULAR PURPOSE.                                  #
#                                                                         #
#   DADF-SDK                                                              #
#                                                                         #
###########################################################################

class IncomingAcceptedTransformer extends IncomingTransformer {
	
	private $table_direction = 'Incoming';
	
	public $accepted_response_id_list = array();
	
	public function __construct($filename, $schema_filename, $table_direction = 'Incoming') {
		
		$this->table_direction = $table_direction;
		
		$xmlservice = new XMLService($filename, $schema_filename);

		$campaignactionresponse_list = $xmlservice->get_node_children($xmlservice->doc, 'campaignactionresponse');

		foreach ($campaignactionresponse_list as $campaignactionresponse):

			$class_name 						= $this->table_direction .  'AcceptedResponse';
			$accepted_response 					= new $class_name();
			
			$acceptid 							= $xmlservice->get_single_child($campaignactionresponse, 'acceptid');
			$id		 							= $xmlservice->get_single_child($campaignactionresponse, 'id');
			$accepted		 					= $xmlservice->get_single_child($campaignactionresponse, 'accepted');
			$reason			 					= $xmlservice->get_single_child($campaignactionresponse, 'reason');
			
			$accepted_response->AcceptID		= $acceptid;
			$accepted_response->ID				= $id;
			$accepted_response->Accepted		= $this->from_boolean($accepted);
			
			if ($reason !== null):
				$accepted_response->Reason			= $reason;
			endif;
			
			$accepted_response->save();
			$column_name = $this->table_direction . 'AcceptedResponseID';
			$this->accept_response_id_list[] 	= $accepted_response->$column_name;	
			
		endforeach;
		
	}	
	
}

